import request from '@/utils/request';
import axios from "axios";

// 公告详情
const getArtcleDetails = async (id) => {
  const url = $globalRequestUrl({
    url: `/article/detail?id=${id}`,
  });
  return await request({
    url,
    method: 'get',
  })
};

// 世界书详情
const getWorldBookDetails = async (id) => {
  const url = $globalRequestUrl({
    url: `/characters/detail?id=${id}`,
  });
  return await request({
    url,
    method: 'get',
  })
};

// 用户世界书导入
const importWorldBook = async (data) => {
  const url = $globalRequestUrl({
    url: `/characters/export`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 用户世界书详情
const getUserWorldBookDetails = async (id) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/detail?id=${id}`,
  });
  return await request({
    url,
    method: 'get',
  })
};

// 世界书列表
const getUserWorldBookList = async (params) => {
  const url = $globalRequestUrl({
    url: `/user/world_role`,
  });

  return await request({
    url,
    method: 'get',
    params
  })
};

// 世界书删除
const deleteWorldBook = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/delete`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 发布 推送角色到首页
const publishWorldRole = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/publish`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 世界书上传图片
const uploadWorldImage = async (formData) => {
  const url = $globalUploaderRequest({
    url: `/upload`,
  });
  return await request({
    url,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
};
// 创建角色
const createWorldRole = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/create`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 编辑角色
const editRole = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/edit`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 编辑世界书
const editWorldRole = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/world_book/edit`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 所有角色的聊天ID
const getWorldBookRoleChatList = async () => {
  const url = $globalRequestUrl({
    url: `/user/world_book/role/chat`,
  });
  return await request({
    url,
    method: 'get',
  })
};
// 发起聊天
const createChat = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/chat/create`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};

// 修改聊天
const editChat = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/chat/group/edit`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 删除角色
const deleteRole = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/delete`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};
// 角色卡详情
const getCardDetails = async (id) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/detail?id=${id}`,
  });
  return await request({
    url,
    method: 'get',
  })
};

// 智能创建
const aiCreate = async (data) => {
  const url = $globalRequestUrl({
    url: `/user/world_role/ai_create`,
  });
  return await request({
    url,
    method: 'post',
    data
  })
};

// 智能创建价格
const aiCreatePrice = async () => {
  const url = $globalRequestUrl({
    url: `/user/world_role/ai_create/price`,
  });
  return await request({
    url,
    method: 'get',
  })
};

//  获取发布分类 此接口与其他接口返回结构不同
const getCategory = async () => {
  const url = $globalRequestUrl({
    url: `/category/world_role`,
  });
  const token = localStorage.getItem("access_token");

  return axios.get(url, {
    headers: {
      "Authorization": `bearer ${token}`,
      "auth_header": `Basic cm9vdDpyb290`,
    }
  })
};

export {
  getArtcleDetails, getWorldBookDetails, getUserWorldBookDetails, getUserWorldBookList,
  uploadWorldImage, importWorldBook, createWorldRole, editWorldRole, getWorldBookRoleChatList, createChat, editChat, deleteWorldBook, deleteRole,
  editRole, publishWorldRole, getCardDetails, aiCreate, aiCreatePrice, getCategory
};
